package com.fone.player.activity.search.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fone.player.ApplicationManage;
import com.fone.player.R;
import com.fone.player.cache.ImageDownloadModule;
import com.fone.player.client.SearchRst.Cnt;

public class ListViewAdapter extends BaseAdapter {

	private List<Cnt> mList;

	public ListViewAdapter(List<Cnt> list) {
		this.mList = list;
	}

	@Override
	public int getCount() {
		int count = 0;
		if (mList != null) {
			count = mList.size();
		}
		return count;
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	ViewHolder viewHolder;

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = LayoutInflater.from(ApplicationManage.getAplicationManageInstance()).inflate(
					R.layout.search_result_listview_item, null);
			viewHolder = new ViewHolder();
			viewHolder.imageview = (ImageView) convertView
					.findViewById(R.id.iv_item);
			viewHolder.tv_name = (TextView) convertView
					.findViewById(R.id.tv_name);
			viewHolder.tv_desc = (TextView) convertView
					.findViewById(R.id.tv_desc);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		Cnt cnt = mList.get(position);
		viewHolder.tv_name.setText(cnt.name);
		viewHolder.tv_desc.setText("类别:"+cnt.type);
		viewHolder.imageview.setImageBitmap(null);
		ImageDownloadModule.getInstance().download(cnt.pic2,
				viewHolder.imageview);
		return convertView;
	}

	static class ViewHolder {
		public ImageView imageview;
		public TextView tv_name;
		public TextView tv_desc;
	}
	
	public void removeData(){
		mList = null;
	}
}
